package zhishuang.wang;

import zhishuang.wang.sansi.fcms.devinfor.DeviceControl;
import zhishuang.wang.sansi.fcms.devinfor.DeviceVar;
import zhishuang.wang.sansi.playlist.AreaItem;
import zhishuang.wang.sansi.playlist.PageItem;
import zhishuang.wang.sansi.playlist.PlayItem;
import zhishuang.wang.sansi.playlist.entry.*;
import zhishuang.wang.sansi.playlist.fcms.PlayListFcms;
import zhishuang.wang.sansi.tools.ReturnData;
import zhishuang.wang.sansi.tools.json.exception.FastjsonUtil;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author Zhishuang.Wang
 * @Date ${DATE} ${TIME}
 * @Email 1406110602@qq.com
 */
public class Main {

    public static void testFcmsPlay() {
        Animation animation = new Animation();
        animation.setInAnimation(00);
        animation.setInAnimationSpeed(20);

        TextBase textBase = new TextBase(0, ".客服电话：3055777!");
        textBase.setFontSize("3232");
        textBase.setFontName("s");
        textBase.setWordSpace(5);
        BaseColour fontColour = new BaseColour(0, 255, 0, 0,0);
        textBase.setFontColour(fontColour);

        PlayTimeBase textPlayTime = new PlayTimeBase(3000);

        PlayItem textPlayItem = new PlayItem(1, "1", "test", textBase, textPlayTime);
        textPlayItem.setAnimation(animation);
//        textPlayItem.setMaterialType(1);
        textPlayItem.setX(10);
        textPlayItem.setY(10);

//        PlayTimeBase pictPlayTime = new PlayTimeBase(30000);
//        PictureBase pictureBase = new PictureBase(0, "r64.bmp");
//        PlayItem picturePlayItem = new PlayItem(2, "picture", "1321321", pictureBase, pictPlayTime);
//        picturePlayItem.setAnimation(animation);

        List<PlayItem> playItemList = new ArrayList();
        playItemList.add(textPlayItem);
//        playItemList.add(picturePlayItem);

//        Background background = new Background();
//        BaseColour backColour = new BaseColour(255, 255, 255, 0,0);
//        background.setBackColour(backColour);
        AreaPositon areaPositon = new AreaPositon(0, 0, 48, 320, 0);
        AreaItem areaItem = new AreaItem("1", "areaItem", areaPositon, playItemList);
//        areaItem.setBackground(background);

        List<AreaItem> areaItemList = new ArrayList();
        areaItemList.add(areaItem);

        PageItem pageItem = new PageItem("1", "pageItem", areaItemList);
        PlayListFcms plf = new PlayListFcms();

        String path = "D:\\workspace\\SanSiCMS\\src\\main\\resources\\play.lst";
        File file = new File(path);
        if(file.exists()) file.delete();

        ReturnData rd = plf.createFcmsPlayList(path, pageItem);
        System.out.println("====" + rd.getCode());
        System.out.println("====" + rd.getMessage());
    }

    public static void testFcmsPlayEg1() {
        Animation animation = new Animation();
        animation.setInAnimation(05);
        animation.setInAnimationSpeed(200);

        TextBase textBase = new TextBase(0, "高速出行 请用晋E行");
        textBase.setFontSize("2424");
        textBase.setFontName("s");
        textBase.setWordSpace(5);
        BaseColour fontColour = new BaseColour(0, 255, 0, 0,0);
        textBase.setFontColour(fontColour);

        PlayTimeBase textPlayTime = new PlayTimeBase(6000);

        PlayItem textPlayItem = new PlayItem(1, "1", "test", textBase, textPlayTime);
        textPlayItem.setAnimation(animation);
        textPlayItem.setX(4);
        textPlayItem.setY(4);


        TextBase textBase2 = new TextBase(0, "路况查询：12328");
        textBase2.setFontSize("2424");
        textBase2.setFontName("s");
        textBase2.setWordSpace(5);
        textBase2.setFontColour(fontColour);

        PlayItem textPlayItem2 = new PlayItem(2, "2", "test2", textBase2, textPlayTime);
        textPlayItem2.setAnimation(animation);
        textPlayItem2.setX(4);
        textPlayItem2.setY(4);

        TextBase textBase3 = new TextBase(0, "救援服务：12122");
        textBase3.setFontSize("2424");
        textBase3.setFontName("s");
        textBase3.setWordSpace(5);
        textBase3.setFontColour(fontColour);

        PlayItem textPlayItem3 = new PlayItem(3, "3", "test3", textBase3, textPlayTime);
        textPlayItem3.setAnimation(animation);
        textPlayItem3.setX(4);
        textPlayItem3.setY(4);


        List<PlayItem> playItemList = new ArrayList();
        playItemList.add(textPlayItem);
        playItemList.add(textPlayItem2);
        playItemList.add(textPlayItem3);


//        Background background = new Background();
//        BaseColour backColour = new BaseColour(255, 255, 255, 0,0);
//        background.setBackColour(backColour);
        AreaPositon areaPositon = new AreaPositon(0, 0, 48, 320, 0);
        AreaItem areaItem = new AreaItem("1", "areaItem", areaPositon, playItemList);
//        areaItem.setBackground(background);

        List<AreaItem> areaItemList = new ArrayList();
        areaItemList.add(areaItem);

        PageItem pageItem = new PageItem("1", "pageItem", areaItemList);
        PlayListFcms plf = new PlayListFcms();

        String path = "D:\\workspace\\SanSiCMS\\src\\main\\resources\\eg1\\play.lst";
        File file = new File(path);
        if(file.exists()) file.delete();

        ReturnData rd = plf.createFcmsPlayList(path, pageItem);
        System.out.println("====" + rd.getCode());
        System.out.println("====" + rd.getMessage());
    }

    public static void main(String[] args) {

//        testFcmsPlayEg1();
//        System.out.println("SUCCESSFUL");

        String deviceId = "1";
        DeviceVar.deviceInforInit(deviceId, 1, "14.88.1.128", 2929, 2048);
        ReturnData rd = null;

//        String path = "D:\\workspace\\SanSiCMS\\src\\main\\resources\\eg1\\play.lst";
//        rd = DeviceControl.fcmsUploadPlayList(deviceId,path);//上传播放表
//        System.out.println("上传播放表 ：" + FastjsonUtil.to(rd));
//        DeviceControl.fcmsActivePlayList(deviceId,"play.lst");
//        System.out.println("激活播放表 ：" + FastjsonUtil.to(rd));

        rd = DeviceControl.fcmsVersionRead(deviceId);
        System.out.println("版本号====" + FastjsonUtil.to(rd));
        String rPath = "D:\\workspace\\SanSiCMS\\src\\main\\resources\\r\\play.lst";
        rd = DeviceControl.fcmsDownFile(deviceId,rPath,"play.lst");//下载文件
        System.out.println("下载文件===="+FastjsonUtil.to(rd));
    }

}